package junior.回溯法;

/**
 * 框架：n个元素中取 r 个， 做允许重复组合，模拟集装箱给轮船的分配。
 * 构造长度为2的 1-2 向量（模拟两艘船），求出全部的解空间（每个解的长度模拟集装箱）
 * 解空间：1-2的全部组合，代表集装箱分配给每个船的全部情况
 */
public class 装载问题01两船 {
    static int[] stack = new int[10000000];
    static int top = 0;
    static int total = 0;
    static int N = 10;
    static int c1 = 50, c2 = 60;
    static int[] weight = {7,12,9,18,9,7,14,9,12,13};
    public static void main(String[] args) {
        fun(0);
        System.out.println(total);
    }

    public static void fun(int n){
        if(n == N){
            int load1 = 0, load2 = 0;
            for (int i = 0; i < top; i++) {
                if(stack[i] == 1)
                    load1 += weight[i];
                else
                    load2 += weight[i];
            }
            if(load1 <= c1 && load2 <= c2){
                System.out.print("c1: "+load1+"\tc2: "+load2+" ::\t");
                for (int i = 0; i < top; i++) {
                    System.out.print(stack[i]+"\t");
                }
                System.out.println();
                total++;
            }
            return;
        }
        for (int i = 1; i <= 2; i++) {
            stack[top++] = i;
            fun(n+1);
            top--;
        }
    }
}
